<template>
  <div class="box">{{ 1 + 1 }}</div>
  <button @click="add">添加</button>
</template>
<script>
  export default {
    data() {
      return {
        a: 1,
        b: 2,
        skills: [
          {
            cd: 0,
            cd_time: 3,
            name: '1'
          },
          {
            cd: 0,
            cd_time: 1,
            name: '2'
          },
          {
            cd: 0,
            cd_time: 3,
            name: '3',
            again: 1
          }
        ],
        nowRound: 0
      }
    },
    methods: {
      add() {
        console.log(`helloworld`)
      }
    },
    mounted() {
      const selectSkill = (i) => {
        console.log(`回合${i}`)
        let skills = this.skills
        let nowSKill = skills
          .filter((res) => {
            return res.cd == 0
          })
          .sort((a, b) => {
            a.again = a.again || 0
            b.again = b.again || 0
            let emA = a.again * 1000 - a.cd_time
            let emB = b.again * 1000 - b.cd_time
            //console.log(emA, emB)
            return emA - emB
          })
        if (nowSKill.length == 0) {
          console.log({
            name: 'common'
          })
          skillQueue.push({
            name: 'common'
          })
          skills.forEach((res) => {
            if (res.cd > 0) {
              res.cd--
            }
          })
        } else {
          let now = nowSKill[0]
          console.log({ ...now })
          skillQueue.push(Object.assign({}, now))
          now.cd = now.cd_time + 1
          skills.forEach((res) => {
            if (res.cd > 0) {
              res.cd--
            }
          })
          if (now.again) {
            selectSkill(i)
          }
        }
      }
      //rule cd_time long first
      let skillQueue = []
      for (var i = 1; i <= 15; i++) {
        selectSkill(i)
      }
      console.log(skillQueue)
    }
  }
</script>
<style type="text/css">
  .box {
    width: 100px;
    height: 100px;
    border: 1px solid #000;
  }
</style>
